home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11283 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  48 lines

  1. Path: ucl.ac.uk!nobody
  2. From: hammond_g@drkclu.meng.ucl.ac.uk (G. Ruth Hammond)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Kind of an annoying question...
  5. Date: Wed, 20 Mar 1996 13:12:51 GMT
  6. Organization: UCL Dept Mech Eng
  7. Message-ID: <1996Mar20.131251.80856@ucl.ac.uk>
  8. NNTP-Posting-Host: crs4gw.crs4.it
  9. Originator: daemon@crs4gw.crs4.it
  10.  
  11.  
  12. In article <4iaqd4$l70@cs3.brookes.ac.uk>, Krunchie <95155580@brookes.ac.uk>
  13. writes:
  14. |>speng@stimpy.us.itd.umich.edu (Steve Palmer Peng) wrote:
  15. |>>I'm wondering, just what function in C allows me to enter a character
  16. |>>from the keyboard, and it automatically executes the command I designate
  17. |>>that character to.  For instance, I have something like,
  18. |>>
  19. |>>printf("Enter Y or N:");
  20. |>>
  21. |>>and I want the command after the printf statement to wait for input
  22. |>>from the keyboard, but once someone enters a Y or an N, the next line of
  23. |>>code is executed, without hitting enter.  Does anyone know how?  It would
  24. |>>be greatly appreciated if someone could help me out here...
  25. |>>
  26. |>>Steve
  27. |>>
  28. |>>
  29. |>Here is an example of how this can easily be achieved:
  30. |>
  31. |>int main(void)
  32. |>{
  33. |>char choice;
  34. |>printf("Do you want to drop an H-Bomb on Iraq (Y or N)");
  35. |>choice=getch(); /* vital line */
  36.          ^^^^^
  37.  
  38. this is not an ANSI function, the FAQ mentions that doing this  is system
  39. specific.
  40.  
  41. -- 
  42. ~GuyRuthHammond () {}
  43. // Machinery and Mayhem at UCL Dept Mech Eng              
  44. // mailto:hammond_g@meng.ucl.ac.uk  http://www.ucl.ac.uk/~zcemm23 
  45. // Clear the DECs, it's time for action!            
  46.  
  47.  
  48.